/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package address;


import equipment.Equipment;


import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.apache.struts2.ServletActionContext;

/**
 *
 * @author PC
 */
public class HistoricSystemAction extends ActionSupport implements ModelDriven<Addresses> {

    private static final long serialVersionUID = 9149826260758390091L;
    private int id_equipment;
    private int id_address;
    private String name_hardware;
    private String cpu;
    private String ram;
    private String lieu;
    private String system_ex;
    private String address;
    private String netmask;
    private String interface_addr;
    private String type_address;
    private List<AddressIp> listAddressIp;
    private List<Process> listProcess;
    private AddressIpDAO addressDao;
    private AddressIp addressIp;
    private Addresses addresses;
    private Equipment equipment;

    @Override
    public String execute() {
        System.out.println("-----method execute");
        AddressIp addressip = new AddressIp(id_address, name_hardware, address, netmask, type_address);
        addressDao = new AddressIpDAO();
        addressDao.add(addressip);
        addressDao.listAddress();
        return SUCCESS;
       
    }
    
    

    public int getId_address() {
        return id_address;
    }

    public void setId_address(int id_address) {
        this.id_address = id_address;
    }
      
    public String getName_hardware() {
        return name_hardware;
    }

    public void setName_hardware(String name_hardware) {
        this.name_hardware = name_hardware;
    }

    public String getCpu() {
        return cpu;
    }

    public void setCpu(String cpu) {
        this.cpu = cpu;
    }

    public String getRam() {
        return ram;
    }

    public void setRam(String ram) {
        this.ram = ram;
    }

    public String getLieu() {
        return lieu;
    }

    public void setLieu(String lieu) {
        this.lieu = lieu;
    }

    public String getSystem_ex() {
        return system_ex;
    }

    public void setSystem_ex(String system_ex) {
        this.system_ex = system_ex;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }
    
    public String getNetmask() {
        return netmask;
    }

    public void setNetmask(String netmask) {
        this.netmask = netmask;
    }
    public String getType_address() {
        return type_address;
    }

    public void setType_address(String type_address) {
        this.type_address = type_address;
    }

    public List<AddressIp> getListAddressIp() {
        return listAddressIp;
    }

    public void setListAddressIp(List<AddressIp> listAddressIp) {
        this.listAddressIp = listAddressIp;
    }  
    
    public String editAddressIp() {
        AddressIpDAO addressIpDao = new AddressIpDAO();
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( ServletActionContext.HTTP_REQUEST);
        System.out.println("id: "+request.getParameter("id_address"));
        addressIp = addressIpDao.getAddressById(Integer.parseInt(request.getParameter("id_address")));
        return SUCCESS;
    }
    
    public String deleteAddressIp() {
        AddressIpDAO addressIpDao = new AddressIpDAO();
        HttpServletRequest request = (HttpServletRequest) ActionContext.getContext().get( ServletActionContext.HTTP_REQUEST);
        addressIpDao.deleteAddress(Integer.parseInt(request.getParameter("id_address")));
        listAddressIp = addressIpDao.listAddress();
        return SUCCESS;
    }

    public AddressIp getAddressIp() {
        return addressIp;
    }

    public void setAddressIp(AddressIp addressIp) {
        this.addressIp = addressIp;
    }

    @Override
    public Addresses getModel() {
        return addresses;
    }
}